package com.sita.car;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class RegisterActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener{	
	
//	LocationClient mLocationClient;
	TelephonyManager telephonyManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
//	mLocationClient = new LocationClient(this, this, this);

	setContentView(R.layout.activity_register);
	String vin = telephonyManager.getSubscriberId();
	TextView vinView = (TextView) findViewById(R.id.car_vin);
	vinView.setText(vin);

	// Trigger to start register activity
	OnClickListener registerListener = new OnClickListener() {	
		@Override
		public void onClick(View v) {			
			Editable phoneNumber = ((EditText) findViewById(R.id.input_phone_number)).getText();	
			
//			Location mCurrentLocation;
//		    mCurrentLocation = mLocationClient.getLastLocation();
			
			Intent intent = new Intent(RegisterActivity.this, ConfirmActivity.class);
			intent.putExtra("phoneNumber", phoneNumber.toString());
//			intent.putExtra("latitude", mCurrentLocation.getLatitude());
//			intent.putExtra("longitude", mCurrentLocation.getLongitude());
			intent.putExtra("vin", telephonyManager.getSubscriberId());
						
			startActivity(intent);
		}
	};
	
	findViewById(R.id.register_button).setOnClickListener(
			registerListener);
	}

	@Override
	public void onConnectionFailed(ConnectionResult arg0) {
		
	}

	@Override
	public void onConnected(Bundle arg0) {
		
	}

	@Override
	public void onDisconnected() {
		
	}
	
//	@Override
//    protected void onStart() {
//        super.onStart();
//        // Connect the client.
//        mLocationClient.connect();
//    }
//	
//	protected void onStop() {
//        // Disconnecting the client invalidates it.
//        mLocationClient.disconnect();
//        super.onStop();
//    }

}
